package day13;
/**
 * 实现输入两个数相加的界面
 */
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JFrame4 {
	public static void main(String[] args) {
		JFrame frame = new JFrame("欢迎");
		JPanel panel = new JPanel();
		frame.add(panel);
		panel.setLayout(new FlowLayout());
		//第一个数字
		JTextField textField1 = new JTextField();
		textField1.setPreferredSize(new Dimension(100, 30));
		panel.add(textField1);
		//+号
		JLabel label = new JLabel("+");
		panel.add(label);
		//第二个数字
		JTextField textField2 = new JTextField();
		textField2.setPreferredSize(new Dimension(100, 30));
		panel.add(textField2);
		//=号
		JButton button = new JButton("=");
		panel.add(button);
		JLabel label2 = new JLabel();
		panel.add(label2);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String num1 = textField1.getText();
				System.out.println(num1);
				String num2 = textField2.getText();
				System.out.println(num2);
				int result = Integer.parseInt(num1) + Integer.parseInt(num2);
				label2.setText(Integer.toString(result));
			}
		});
		frame.setSize(500, 500);
		frame.setLocation(500, 450);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
